package pp.strategy.worktime;

import lombok.Data;
import pp.IWorkTimeStrategy;
import pp.PowerProject;
import properties.AutoBGProperties;
import properties.WorkTimeBean;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Data
public class AllAutoWorkTimeStrategy implements IWorkTimeStrategy {

    private PowerProject pp;

    @Override
    public Map<String, WorkTimeBean> workTime(AutoBGProperties autoBGProperties) {
        Map<String, WorkTimeBean> workTimeBeans = new HashMap<>(7);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = null;
        try {
            parse = sdf.parse(autoBGProperties.getFirstDay());
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        for (int i = 0; i < 5; i++) {
            String dateFormat = sdf.format(new Date(parse.getTime() + (3600L * 24 * 1000) * i));
            WorkTimeBean weekBean = null;
            try {
                weekBean = new WorkTimeBean("7.5", "0", pp.selectTask().getName() + "-" + dateFormat);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            workTimeBeans.put(dateFormat, weekBean);
        }
        return workTimeBeans;
    }
}
